﻿using UnityEngine;

namespace HotPlayer.Physic2D
{
    public class HotPhysic2DUtils
    {
        public static Vector3[] ConvertToVec3XZ(Vector2[] inputPoints)
        {
            var points = new Vector3[inputPoints.Length];
            for (int i = 0; i < inputPoints.Length; i++)
            {
                points[i] = new Vector3(inputPoints[i].x, 0, inputPoints[i].y);
            }
            return points;
        }

        public static Vector3[] ConvertXZ(Transform[] transforms)
        {
            var points = new Vector3[transforms.Length];
            for (int i = 0; i < transforms.Length; i++)
            {
                points[i] = transforms[i].position;
            }
            return points;
        }
        
        public static Vector2[] ConvertTransformXZ(Transform[] transforms)
        {
            var points = new Vector2[transforms.Length];
            for (int i = 0; i < transforms.Length; i++)
            {
                var position = transforms[i].position;
                points[i] = new Vector2(position.x, position.z);
            }

            return points;
        }
        
        public static Vector2[] ConvertXZ(Vector3[] fromPoints)
        {
            var points = new Vector2[fromPoints.Length];
            for (int i = 0; i < fromPoints.Length; i++)
            {
                var position = fromPoints[i];
                points[i] = new Vector2(position.x, position.z);
            }

            return points;
        }

        public static Vector3[] Translate(Vector3[] points, Vector3 offset)
        {
            var newPoints = new Vector3[points.Length];
            for (int i = 0; i < points.Length; i++)
            {
                newPoints[i] = points[i] + offset;
            }
            return newPoints;
        }
    }
}